﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
using System.Data;
using Dal;
using System.Data.SqlClient;
using DataAccess.SqlClient;
using ApiDAL.Common;
namespace Dal
{
   public  class MenuDAL
   {
       #region 菜单显示
       /// <summary>
       /// 菜单显示
       /// </summary>
       /// <param name="tid"></param>
       /// <returns></returns>
       public List<Menu> Menushow()
       {
           SqlQuery sql = new SqlQuery();
           sql.CommandText  = string.Format("select * from Menu");
           DataSet ds = SqlDataAccess.ExecDataset(sql);
           DataTable dt = ds.Tables[0];
           return DataReaderToObjectHelper.DataTableToList<Menu>(dt);

       }
       #endregion

       #region 添加购物车
       /// <summary>
       /// 添加购物车
       /// </summary>
       /// <param name="jia"></param>
       /// <returns></returns>

       public int addcar(int CarId, string CarName, string CarPhoto, string CarDescrib, decimal CarPrice, int CarNum, int UserId)
       {
           SqlQuery sql = new SqlQuery();
           sql.CommandText = "caradd";
           sql.CommandType = CommandType.StoredProcedure;
           SqlParameter cc = new SqlParameter();
           cc.Value = CarId;
           cc.ParameterName = "@CarId";
           cc.SqlDbType = System.Data.SqlDbType.VarChar;
           sql.Parameters.Add(cc);

           SqlParameter cc1 = new SqlParameter();
           cc1.Value = CarName;
           cc1.ParameterName = "@CarName";
           cc1.SqlDbType = System.Data.SqlDbType.VarChar;
           sql.Parameters.Add(cc1);
           SqlParameter cc2 = new SqlParameter();
           cc2.Value = CarPhoto;
           cc2.ParameterName = "@CarPhoto";
           cc2.SqlDbType = System.Data.SqlDbType.VarChar;
           sql.Parameters.Add(cc2);
           SqlParameter cc3 = new SqlParameter();
           cc3.Value = CarDescrib;
           cc3.ParameterName = "@CarDescrib";
           cc3.SqlDbType = System.Data.SqlDbType.VarChar;
           sql.Parameters.Add(cc3);

           SqlParameter cc4 = new SqlParameter();
           cc4.Value = CarPrice;
           cc4.ParameterName = "@CarPrice";
           cc4.SqlDbType = System.Data.SqlDbType.VarChar;
           sql.Parameters.Add(cc4);

           SqlParameter cc5 = new SqlParameter();
           cc5.Value = CarNum;
           cc5.ParameterName = "@CarNum";
           cc5.SqlDbType = System.Data.SqlDbType.VarChar;
           sql.Parameters.Add(cc5);

           SqlParameter cc6 = new SqlParameter();
           cc6.Value = UserId;
           cc6.ParameterName = "@UserId";
           cc6.SqlDbType = System.Data.SqlDbType.VarChar;
           sql.Parameters.Add(cc6);

           int i = Convert.ToInt32(SqlDataAccess.ExecScalar(sql));
           return i;


       }
       #endregion

       #region 菜单分类
       /// <summary>
       /// 菜单分类
       /// </summary>
       /// <param name="id"></param>
       /// <returns></returns>

       public List<Menu> menutype(int id)
       {
           SqlQuery sql = new SqlQuery();
           sql.CommandText = "select * from Menu where tid='"+id+"'";
           DataSet ds = SqlDataAccess.ExecDataset(sql);
           DataTable dt = ds.Tables[0];
           return DataReaderToObjectHelper.DataTableToList<Menu>(dt);

       }
       #endregion

       #region 根据菜单表MenuId 查找数据
       /// <summary>
       /// 根据菜单表MenuId 查找数据
       /// </summary>
       /// <param name="id"></param>
       /// <returns></returns>
       public List<Menu> carshow(int id)
       {
           SqlQuery sql = new SqlQuery();
           sql.CommandText = "select * from Menu where MenuId='" + id + "'";
           DataSet ds = SqlDataAccess.ExecDataset(sql);
           DataTable dt = ds.Tables[0];
           return DataReaderToObjectHelper.DataTableToList<Menu>(dt);
       
       }
       #endregion

       #region 删除菜单信息
       /// <summary>
       /// 删除菜单信息
       /// </summary>
       /// <param name="id"></param>
       /// <returns></returns>
       public int delete(int id)
       {
           SqlQuery sql = new SqlQuery();
           sql.CommandText = "delete from Menu where MenuId='" + id + "'";
           return SqlDataAccess.ExecNonQuery(sql);
      
       }
       #endregion

       #region 菜单添加
       /// <summary>
       /// 菜单添加
       /// </summary>
       /// <param name="n"></param>
       /// <returns></returns>
       public int addMen(Menu n)
       {
           SqlQuery sql = new SqlQuery();
           sql.CommandText = "insert into [Menu] values('" + n.MenuName + "','" + n.MenuPhoto + "','" + n.MenuDescrib + "'," + n.MenuPrice + ","+n.Tid+")";
           return SqlDataAccess.ExecNonQuery(sql);

       }
       #endregion

       #region 修改菜单
       /// <summary>
       /// 修改菜单
       /// </summary>
       /// <param name="gai"></param>
       /// <returns></returns>


       public int update(string MenuName, string MenuPhoto, string MenuDescrib, string MenuPrice, int MenuId)
       {
           SqlQuery sql = new SqlQuery();
           sql.CommandText = "update Menu set Menuname='" + MenuName + "',MenuPhoto='" + MenuPhoto + "',MenuDescrib='" + MenuDescrib + "',MenuPrice='" + MenuPrice + "' where MenuId=" + MenuId + "";
           return SqlDataAccess.ExecNonQuery(sql);
       }

       #endregion




   }
}
